<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class CetakRekap extends zulController {
	function __construct(){
		parent::__construct();
		// $this->checkLogin();
		$this->load->library("form_validation");
	}
	public function pasien()
	{
		$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
		$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		$this->form_validation->set_message('required','Kolom %s harus diisi !');
		$this->form_validation->set_error_delimiters('<div class="alert alert-error fade in"><button type="button" class="close" data-dismiss="alert">&times;</button>', '</div>');
		if($this->form_validation->run() == FALSE) {
			$data["active"] = "report";
			$data["jRekap"]	= false;
			$data["content"]= $this->load->view("formRekap",$data,true);
			$this->load->view('main_new',$data);
		} else {
			$this->load->model("PasienModel");
			$data["tgl_awal"]	= date("Y-m-d",strtotime($this->input->post("tgl_awal")));
			$data["tgl_akhir"]	= date("Y-m-d",strtotime($this->input->post("tgl_akhir")));
			$data["getPasien"]	= $this->PasienModel->get_by(array("TGL_DAFTAR >= "=>$data["tgl_awal"],"TGL_DAFTAR <= "=>$data["tgl_akhir"]));
			$this->load->library("phpexcel");
			$this->load->library("PHPExcel/IOFactory");
			$this->load->view("excel_pasien",$data);
		}
	}
	public function pengeluaranObat(){
		$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
		$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		$this->form_validation->set_rules("jenis","Jenis Poli","required");
		$this->form_validation->set_message('required','Kolom %s harus diisi !');
		$this->form_validation->set_error_delimiters('<div class="alert alert-error fade in"><button type="button" class="close" data-dismiss="alert">&times;</button>', '</div>');
		if($this->form_validation->run() == FALSE) {
			$data["active"] = "report";
			$data["jRekap"]	= "Pengeluaran";
			$data["content"]= $this->load->view("formRekap",$data,true);
			$this->load->view('main_new',$data);
		} else {
			$this->load->library("phpexcel");
			$this->load->library("PHPExcel/IOFactory");
			$this->load->model("DetailPengeluaranModel","detail_resep");
			$this->load->model("PengeluaranObatModel","resep");
			$data["tgl_awal"]	= $this->input->post("tgl_awal");
			$data["tgl_akhir"]	= $this->input->post("tgl_akhir");
			$jenis		= $this->input->post("jenis");
			if($jenis == 2){
				$data["getResep"]	= $this->resep->get_group(array("TGL_RESEP >= "=>$data["tgl_awal"],"TGL_RESEP <= "=>$data["tgl_akhir"]),"TGL_RESEP");
				$this->load->view("excel_pengeluaran_all",$data);
			} else {
				$data["getResep"]	= $this->resep->get_group(array("TGL_RESEP >= "=>$data["tgl_awal"],"TGL_RESEP <= "=>$data["tgl_akhir"],"JENIS"=>$jenis),"TGL_RESEP");
				$this->load->view("excel_pengeluaran",$data);
			}
		}
	}
	public function penerimaanObat(){
		$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
		$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		$this->form_validation->set_message('required','Kolom %s harus diisi !');
		$this->form_validation->set_error_delimiters('<div class="alert alert-error fade in"><button type="button" class="close" data-dismiss="alert">&times;</button>', '</div>');
		if($this->form_validation->run() == FALSE) {
			$data["active"] = "report";
			$data["jRekap"]	= false;
			$data["content"]= $this->load->view("formRekap",$data,true);
			$this->load->view('main_new',$data);
		} else {
			$this->load->model("DetailPenerimaanModel","detail_terima");
			$this->load->model("PenerimaanObatModel","terima");
			$data["tgl_awal"]	= date("Y-m-d",strtotime($this->input->post("tgl_awal")));
			$data["tgl_akhir"]	= date("Y-m-d",strtotime($this->input->post("tgl_akhir")));
			$data["getTerima"]	= $this->terima->get_group(array("TGL_PENERIMAAN >= "=>$data["tgl_awal"],"TGL_PENERIMAAN <= "=>$data["tgl_akhir"]),"TGL_PENERIMAAN");
			$this->load->library("phpexcel");
			$this->load->library("PHPExcel/IOFactory");
			$this->load->view("excel_penerimaan",$data);
		}
	}
	public function kartuStok(){
		$this->load->model("ObatModel");
		$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
		$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		$this->form_validation->set_rules("nama_obat","Nama Obat","required");
		$this->form_validation->set_message('required','Kolom %s harus diisi !');
		$this->form_validation->set_error_delimiters('<div class="alert alert-error fade in"><button type="button" class="close" data-dismiss="alert">&times;</button>', '</div>');
		if($this->form_validation->run() == FALSE) {
			$data["active"] = "report";
			$data["jRekap"]	= "kartuStok";
			$data["getObat"]	= $this->ObatModel->get(FALSE,FALSE);
			$data["content"]= $this->load->view("formRekap",$data,true);
			$this->load->view('main_new',$data);
		} else {
			$this->load->library("phpexcel");
			$this->load->library("PHPExcel/IOFactory");
			$this->load->model("DetailPengeluaranModel","keluar");
			$this->load->model("DetailPenerimaanModel","masuk");
			$this->load->model("DetailPenyesuaianModel","adjust");
			$nama_obat			= $this->input->post("nama_obat");
			$data["getObat"]	= $this->ObatModel->get($nama_obat,TRUE);
			$data["tgl_awal"]	= date("Y-m-d",strtotime($this->input->post("tgl_awal")));
			$data["tgl_akhir"]	= date("Y-m-d",strtotime($this->input->post("tgl_akhir")));
			
			$data["getTgl"]	= $this->ObatModel->get_tgl($data["tgl_awal"],$data["tgl_akhir"],$nama_obat);
			$this->load->view("excel_kartu_stok",$data);
		}
	}
	public function stokObat(){
		$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
		$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		$this->form_validation->set_message('required','Kolom %s harus diisi !');
		$this->form_validation->set_error_delimiters('<div class="alert alert-error fade in"><button type="button" class="close" data-dismiss="alert">&times;</button>', '</div>');
		if($this->form_validation->run() == FALSE) {
			$data["active"] = "report";
			$data["jRekap"]	= false;
			$data["content"]= $this->load->view("formRekap",$data,true);
			$this->load->view('main_new',$data);
		} else {
			$this->load->model("DetailPengeluaranModel","keluar");
			$this->load->model("DetailPenerimaanModel","masuk");
			$this->load->model("DetailPenyesuaianModel","adjust");
			$this->load->model("ObatModel","obat");
			$data["tgl_awal"]	= date("Y-m-d",strtotime($this->input->post("tgl_awal")));
			$data["tgl_akhir"]	= date("Y-m-d",strtotime($this->input->post("tgl_akhir")));
			$data["getObat"]	= $this->obat->get(FALSE,FALSE);
			$this->load->library("phpexcel");
			$this->load->library("PHPExcel/IOFactory");
			$this->load->view("excel_stok_obat",$data);
		}
	}
}